package com.ellison.springboot.expandsboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.SpringApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * <p>ApplicationListener 扩展
 *
 * @author Ellison_Pei
 * @date 2022/3/28 16:32
 * @since 1.0
 **/
public class CustomApplicationListener implements ApplicationListener<CustomEvent> {

    @Override
    public void onApplicationEvent(CustomEvent event) {
        System.out.println("========CustomApplicationListener.onApplicationEvent()=============");
    }
}

@SuppressWarnings("serial")
class CustomEvent extends SpringApplicationEvent {

    private final ConfigurableApplicationContext context;

    public CustomEvent(SpringApplication application, String[] args,
                       ConfigurableApplicationContext context) {
        super(application, args);
        this.context = context;
    }

    public ConfigurableApplicationContext getApplicationContext() {
        return this.context;
    }

}
